package com.storm.auth.service

import com.storm.auth.behavior.factory.UserEntityFactory
import com.storm.auth.model.data.JwtUser
import com.storm.util.log
import org.springframework.stereotype.Service

/**
 * 用户认证登入相关接口
 */
@Service
class AuthService(private val userEntityFactory: UserEntityFactory) {
    /**
     * 获取Jwt用户信息
     * @param loginName 用户名
     */
    fun getJwtUserByLoginName(loginName: String): JwtUser? {
        log.info("用户名为：{}", loginName)

        val userEntity = userEntityFactory.getUserEntityByUsername(loginName)

        return userEntity
            .let {
                it.user?.let { user ->
                    JwtUser(
                        user.userId,
                        user.username,
                        user.password,
                        enabled = user.enabled,
                        resources = it.getResources()
                    )
                }
            }
    }

}


fun main() {



}
